package com.db.addrbook;

import java.util.*;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

public class CategoryDAO {
	private SqlMapClientTemplate template;
	
	public void setTemplate(SqlMapClientTemplate template) {
		this.template = template;
	}

	// 타입 구분없는 전체 분류 리스트
	@SuppressWarnings("unchecked")
	public List<CategoryVO> getCategoryList(){
		List<CategoryVO> list = new ArrayList<CategoryVO>();
		try {
			list = template.queryForList("getCategoryList");
		} catch (Exception e) {
			System.out.println("CategoryDAO.getCategoryList():"+e.toString());
		}
		return list;
	}
	// 타입값을 입력받아 해당 타입의 분류목록 만을 리턴하는 메소드
	@SuppressWarnings("unchecked")
	public List<CategoryVO> getCategoryList(int type){
		List<CategoryVO> list = new ArrayList<CategoryVO>();
		try {
			list = template.queryForList("getCategoryByType", type);
		} catch (Exception e) {
			System.out.println("CategoryDAO.getCategoryList():"+e.toString());
		}
		return list;
	}	
	
	public int getCateType(int cno){
		int result = 0;
		try {
			result = ((Integer)template.queryForObject("getCateType", cno)).intValue();
		} catch (Exception e) {
			System.out.println("CategoryDAO.getCateType():"+e.toString());
		}
		return result;
	}
	
	public CategoryVO  getCategoryInfo(int cno){
		CategoryVO cvo = new CategoryVO();
		try {
			cvo = (CategoryVO) template.queryForObject("getCategoryInfo", cno);
		} catch (Exception e) {
			System.out.println("CategoryDAO.getCategoryInfo():"+e.toString());
		}
		return cvo;
	}
	
	public void insertCategory(CategoryVO vo){
		try {
			template.insert("insertCategory", vo);
		} catch (Exception e) {
			System.out.println("CategoryDAO.insertCategory():"+e.toString());
		}
	}
	
	public void updateCategory(CategoryVO vo){
		try {
			template.update("updateCategory", vo);
		} catch (Exception e) {
			System.out.println("CategoryDAO.updateCategory():"+e.toString());
		}		
	}
	
	public void deleteCategory(int cno){
		try {
			template.delete("deleteCategory", cno);
		} catch (Exception e) {
			System.out.println("CategoryDAO.deleteCategory():"+e.toString());
		}			
	}
}
